package com.houweishi.module.postInfo.controller;

import com.houweishi.common.annotation.Log;
import com.houweishi.common.core.controller.BaseController;
import com.houweishi.common.core.domain.AjaxResult;
import com.houweishi.common.core.page.TableDataInfo;
import com.houweishi.common.enums.BusinessType;
import com.houweishi.common.utils.poi.ExcelUtil;
import com.houweishi.module.postInfo.domain.PostInfo;
import com.houweishi.module.postInfo.service.IPostInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 岗位信息Controller
 * 
 * @author yqq
 * @date 2023-07-01
 */
@RestController
@RequestMapping("/module/postInfo")
public class PostInfoController extends BaseController
{
    @Autowired
    private IPostInfoService postInfoService;

    /**
     * 查询岗位信息列表
     */
    @PreAuthorize("@ss.hasPermi('module:postInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(PostInfo postInfo)
    {
        startPage();
        List<PostInfo> list = postInfoService.selectPostInfoList(postInfo);
        return getDataTable(list);
    }

    /**
     * 导出岗位信息列表
     */
    @PreAuthorize("@ss.hasPermi('module:postInfo:export')")
    @Log(title = "岗位信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PostInfo postInfo)
    {
        List<PostInfo> list = postInfoService.selectPostInfoList(postInfo);
        ExcelUtil<PostInfo> util = new ExcelUtil<PostInfo>(PostInfo.class);
        util.exportExcel(response, list, "岗位信息数据");
    }

    /**
         * 获取岗位信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:postInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(postInfoService.selectPostInfoById(id));
    }

    /**
     * 新增岗位信息
     */
    @PreAuthorize("@ss.hasPermi('module:postInfo:add')")
    @Log(title = "岗位信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PostInfo postInfo)
    {
        return toAjax(postInfoService.insertPostInfo(postInfo));
    }

    /**
     * 修改岗位信息
     */
    @PreAuthorize("@ss.hasPermi('module:postInfo:edit')")
    @Log(title = "岗位信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PostInfo postInfo)
    {
        return toAjax(postInfoService.updatePostInfo(postInfo));
    }

    /**
     * 删除岗位信息
     */
    @PreAuthorize("@ss.hasPermi('module:postInfo:remove')")
    @Log(title = "岗位信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(postInfoService.deletePostInfoByIds(ids));
    }
}
